import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class HumanStrategy implements IPlayerStrategy {
	private List<Card> cards;
	
	public HumanStrategy()
	{
	}
	
	@Override
	public final List<Card> getCardsToExchange(final int min, final int max) {
		Iterator<Card> iter = cards.iterator();
		
		System.out.println("Your cards: " + cards.size());
		
		int i = 1;
		while(iter.hasNext()) {
			Card card = iter.next();
			System.out.println(i + ": " + card.toString());
			i++;
		}
		
		System.out.println("Choose cards numbers to exchange (you can exchange from " + min + " to " + max + " cards");
		
		Scanner in = new Scanner(System.in);
		int cardsNumber = -1;
		
		while(cardsNumber < min || cardsNumber > max) {
			System.out.println("How many cards?");
			cardsNumber = in.nextInt();
		}
		
		int card;
		
		List<Card> cardsToExchange = new LinkedList<Card>();
		boolean[] choosenCards = new boolean[cards.size()];
		
		for(int j = 0; j < cardsNumber; j++) {
			card = -1;
			while(card < 0 || card > cards.size()-1 || choosenCards[card]) {
				System.out.println("Give card number between 1 and " + cards.size());
				card = in.nextInt()-1;
			}
			choosenCards[card] = true;
			cardsToExchange.add(cards.get(card));
		}
		
		in.close();
		
		return cardsToExchange;
	}

	@Override
	public final void giveCards(final List<Card> cards) {
		this.cards = cards;
	}

	@Override
	public int sendBet() {
		// TODO Auto-generated method stub
		return 0;
	}

}
